using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {
	
	float playerSpeed = 6f;
	float playerRotation = 5f;
    float playerJumpHeight = 8f;
    float gravity = 20f;
    private Vector3 moveDirection = Vector3.zero;
    
	void Start(){
		
	}
	
	void Update() {
		
		float rotation;
		
        CharacterController controller = GetComponent<CharacterController>();
        if (controller.isGrounded) {
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            moveDirection *= playerSpeed;
            if (Input.GetButton("Jump"))
                moveDirection.y = playerJumpHeight;
        }
		
        moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(moveDirection * Time.deltaTime);
		
		rotation = Input.GetAxis ("Mouse X") * playerRotation * Time.deltaTime;
		transform.Rotate (0,rotation,0);
    }
}
